import omit from 'lodash/omit'
import { ManageMiniprogramsInner } from '@/desktop/components/ManageMiniprograms'
import type { MiniProgramWord } from '@/services/common/definition'
import type { SavedMiniProgram } from '@/services/resources/mini-programs'

export default function EditMp(props: {
  word: MiniProgramWord
  onSave: (word: MiniProgramWord) => void
  onCancel: () => void
}) {
  const { word: initialWord, onSave, onCancel } = props
  const onChoose = (choosed: SavedMiniProgram) =>
    onSave({ ...initialWord, ...omit(choosed, 'id', 'type') })
  return <ManageMiniprogramsInner onClose={onCancel} choose={{ text: '选择', action: onChoose }} />
}
